﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FeatureEdit.aspx.cs" Inherits="NegevGas.Extensions.FeatureEdit.FeatureEdit" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>כרטיס מידע</title>
    <link href="FeatureView.css" rel="stylesheet" type="text/css" />

    <script language="javascript" type="text/javascript">
        if (parent.document.all.tags("Frameset").item(1) != null) {
            parent.document.all.tags("Frameset").item(1).cols = '*,260';
        }
        else {
            parent.parent.document.all.tags("Frameset").item(1).cols = '*,260';
        }
    </script>

    <script language="javascript" type="text/javascript">
        var currentProperty = "";
        var currentDdl;

        function ShowSdfEditorDialog(propertyName, ddl) {
            var listConstraints = document.getElementById("listConstraints");
            listConstraints.innerHTML = "";

            var SdfFileName = document.getElementById("SdfFileName");
            if (propertyName.substring(0, 3) == 'FK_') {
                SdfEditor.NfcGetAllEntries(encodeURI(SdfFileName.value), propertyName.split('_')[1], onOpenDialogWithJsonComplete, onError);
                document.getElementById("btnRename").style.dlsplay = "block";
            }
            else {
                SdfEditor.GetConstraints(encodeURI(SdfFileName.value), propertyName, onOpenDialogComplete, onError);
            }
            currentProperty = propertyName;
            currentDdl = ddl;
        }
        function onOpenDialogComplete(result) {
            var sdfEditorDialog = document.getElementById("sdfEditorDialog");
            var listConstraints = document.getElementById("listConstraints");
            for (var i = 0; i < result.length; i++) {
                var opt = document.createElement("option");
                opt.text = opt.value = result[i];
                listConstraints.add(opt);
            }
            sdfEditorDialog.style.display = "block";
        }
        function onOpenDialogWithJsonComplete(result) {
            var sdfEditorDialog = document.getElementById("sdfEditorDialog");
            var listConstraints = document.getElementById("listConstraints");
            var jsonResult = JSON.parse(result);
            for (var i = 0; i < jsonResult.length; i++) {
                var opt = document.createElement("option");
                var tmp = jsonResult[i].split(', ');
                var val = tmp[0].substr(1, tmp[0].length);
                var txt = tmp[1].substr(0, tmp[1].length - 1);
                opt.text = txt;
                opt.value = val;
                listConstraints.add(opt);
            }
            sdfEditorDialog.style.display = "block";
        }
        function HideSdfEditorDialog() {
            var sdfEditorDialog = document.getElementById("sdfEditorDialog");
            sdfEditorDialog.style.display = "none";
        }

        //Add constraint
        function AddConstraint(id) {
            var SdfFileName = document.getElementById("SdfFileName");
            var newConstraint = document.getElementById("txtNewConstraint").value;
            if (newConstraint.length == 0 || currentProperty == "") return;
            if (id > 0) {
                if (currentProperty.substring(0, 3) == 'FK_') {
                    SdfEditor.NfcRenameEntry(encodeURI(SdfFileName.value), currentProperty.split('_')[1], id, newConstraint, onRenameContraintComplete, onError);
                }
            }
            else {
                if (currentProperty.substring(0, 3) == 'FK_') {
                    SdfEditor.NfcAddNewEntry(encodeURI(SdfFileName.value), currentProperty.split('_')[1], encodeURI(newConstraint), onAddConstraintComplete, onError);
                }
                else {
                    SdfEditor.AddNewConstraint(encodeURI(SdfFileName.value), currentProperty, encodeURI(newConstraint), onAddConstraintComplete, onError);
                }
            }
        }
        function onAddConstraintComplete(result) {
            if ((result == true) || (result != 0 && result - 0 == result && result.toString().length > 0)) {
                var ddl = document.getElementById(currentDdl);

                var newConstraint = document.getElementById("txtNewConstraint").value;
                var listConstraints = document.getElementById("listConstraints");
                var opt2 = document.createElement("option");
                opt2.text = newConstraint;
                opt2.value = result.toString().toLowerCase() == "true" ? newConstraint : result;
                var opt3 = document.createElement("option");
                opt3.text = newConstraint;
                opt3.value = result.toString().toLowerCase() == "true" ? newConstraint : result;

                ddl.add(opt2);
                listConstraints.add(opt3);
                document.getElementById("txtNewConstraint").value = "";
            }
        }

        //Delete constraint
        function DeleteConstraint() {
            var res = confirm("פעולה הזו יכולה להשפיע לרע. להמשיך?");
            if (res && document.getElementById("listConstraints").selectedIndex != -1) {
                var SdfFileName = document.getElementById("SdfFileName");
                var list = document.getElementById("listConstraints");
                var constraint = list.value;
                var txt = list.options[list.options.selectedIndex].text;
                if (constraint.length == 0 || currentProperty == "") return;
                if (currentProperty.substring(0, 3) == 'FK_') {
                    SdfEditor.NfcDeleteEntryByName(encodeURI(SdfFileName.value), currentProperty.split('_')[1], encodeURI(txt), onDeleteConstraintComplete, onError);
                }
                else {
                    SdfEditor.DeleteConstraint(encodeURI(SdfFileName.value), currentProperty, encodeURI(constraint), onDeleteConstraintComplete, onError);
                }
            }
        }
        function onDeleteConstraintComplete(result) {
            if (result == true) {
                var constraint = document.getElementById("listConstraints").value;
                var listConstraints = document.getElementById("listConstraints");
                var ddl = document.getElementById(currentDdl);
                ddl.remove(listConstraints.selectedIndex);
                listConstraints.remove(listConstraints.selectedIndex);
            }
        }
        //Rename  constraint
        function RenameConstraint() {
            if (currentProperty.substring(0, 3) == 'FK_') {
                var list = document.getElementById("listConstraints");
                var btnAdd = document.getElementById("btnAddNewConstraint");
                btnAdd.value = "עדכן";
                btnAdd.onclick = function () { AddConstraint(list.value); }
                var txtValue = document.getElementById("txtNewConstraint");
                txtValue.value = list.options[list.options.selectedIndex].text;
                var btnRename = document.getElementById("btnRename");
                btnRename.value = "ביטול";
                btnRename.onclick = ResetRename;
            }
        }

        function ResetRename() {
            var btnAdd = document.getElementById("btnAddNewConstraint");
            btnAdd.value = "הוסף";
            btnAdd.onclick = AddConstraint;
            document.getElementById("txtNewConstraint").value = "";
            var btnRename = document.getElementById("btnRename");
            btnRename.value = "עדכון";
            btnRename.onclick = RenameConstraint;
        }

        function onRenameContraintComplete(result) {
            if (result == true) {
                var value = document.getElementById("txtNewConstraint").value;
                var list = document.getElementById("listConstraints");
                var ddl = document.getElementById(currentDdl);
                list.options[list.options.selectedIndex].text = value;
                ddl.options[list.options.selectedIndex].text = value;
            }
            ResetRename();
        }

        function onError(result) {
            alert(result._message);
        }
    </script>

</head>
<body dir="rtl">
    <form id="form1" runat="server">
 
    <div class="Header">
        כרטיס מידע<br />
        <asp:Label ID="_HeaderText" runat="server"></asp:Label>
    </div>
    <div>
    <!--
     background: none repeat scroll 0 0 #EBEFF9;
    border-bottom: 1px solid #6B90DA;
    padding: 5px 10px 0 5px;
    white-space: nowrap;
    -->
        <asp:DetailsView ID="_FeatureCard" runat="server" EnableViewState="true" Height="50px"
            Width="100%" dir="rtl" GridLines="None">
            <FooterStyle BackColor="#990000" ForeColor="White" Font-Bold="True" />
            <CommandRowStyle HorizontalAlign="Center" />
            <RowStyle  BackColor="#EBEFF9" ForeColor="#333333" Font-Size="12px" BorderStyle="Solid" BorderWidth="1px" BorderColor="#6B90DA" />

            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <FieldHeaderStyle Font-Names="Arial" BackColor="#FFFFFF" Font-Bold="true" Font-Overline="false"
                Wrap="true" />
            <EditRowStyle Wrap="true" />
            <AlternatingRowStyle BackColor="white" ForeColor="#000000" BorderStyle="Solid" BorderWidth="1px" BorderColor="#6B90DA"/>
        </asp:DetailsView>
    </div>
    <!--  background: none repeat scroll 0 0 #EBEFF9;
    border-bottom: 1px solid #6B90DA; -->
    <asp:Panel ID="SdfEditorPanel" runat="server" Visible="false">
        <div id="sdfEditorDialog" style="display: none" class="dialog">
            <div class="smallHeader">
                עדכון אפשרויות בחירה
                <div class="closeButton" onclick="HideSdfEditorDialog()">
                    X</div>
            </div>
            <div style="width: 100%; padding: 0px 10px 0px 10px">
                <table width="90%">
                    <tr>
                        <td>
                            <input type="text" id="txtNewConstraint" style="width: 100%" />
                        </td>
                        <td width="20px">
                            <input type="button" id="btnAddNewConstraint" value="הוסף" onclick="AddConstraint()" />
                        </td>
                    </tr>
                </table>
            </div>
            <div style="width: 100%; text-align: center; padding: 0px 10px 0px 10px">
                <select id="listConstraints" multiple="multiple" class="list">
                </select>
            </div>
            <div style="width: 100%; padding: 0px 10px 10px 10px;" runat="Server" id="isedit">
                <input type="button" id="btnDelete" value="מחק" onclick="DeleteConstraint()" />
                <input type="button" id="btnRename" value="עדכון" onclick="RenameConstraint()" />
            </div>
            <asp:HiddenField ID="SdfFileName" runat="server" />
   
        </div>
    </asp:Panel>

  
    
    </form>
</body>
</html>
